<meta charset="UTF-8">
<script>
  let arr = []
  arr.push({ id: 0, title: '首页', active: true })
  arr.push({ id: 1, title: '搜索', active: false })
  arr.push({ id: 2, title: '热点', active: true })
  arr.push({ id: 3, title: '沃的', active: false })
  //测试元素是否符合指定的条件，都符合返回true，否则返回false
  let flag = arr.every(item => item.active === true)
  //console.log(flag)
  let index = arr.findIndex(item => item.id === 2)
  //在指定的下标删除几个元素，返回被删除的元素，原数组发生减容操作
  //let element = arr.splice(index, 1)
  //console.log(element)
  //console.log(arr)

  //深copy
  let arr1 = JSON.parse(JSON.stringify(arr))
  arr1.splice(index, 1)
  //console.log(arr)
  console.log(arr1)

  let arr2 = arr1.filter(item => {
    return item.active === false
  })
  console.log(arr2)

  //使用自定义的函数
  Array.prototype.add = function(item) {
    this.push(item)
  }
  Array.prototype.set = function(index, item) {
    this[index] = item
  }

  arr1.add({ id: 2, title: '热点', active: true })
  console.log(arr1)

  arr1.set(arr1.length - 2, { id: 3, title: '我的', active: false })
  console.log(arr1)

  function getObject(name, age) {
    return { name, age }
  }

  let fn = (name, age) => ({ name, age })

  console.log(fn('tom', 20))

</script>
